home *** CD-ROM | disk | FTP | other *** search
/ Windows 95 API Bible / Windows 95 API Bible 3 Disc Set.iso / Win32 API Bible Book 3 of 3 / CHAPTE10 / GETCNTRY / LINE.C < prev    next >
C/C++ Source or Header  |  1996-04-28  |  25KB  |  765 lines

  1.  
  2. #include <windows.h> 
  3. #include <windowsx.h> 
  4. #include "line.h" 
  5. #include "tapi.h"
  6.  
  7. #define BUFSIZE 256
  8. #define APIHIVERSION     0x00010028    /* 1.40 */
  9. #define APILOWVERSION    0x00010000    /* 1.0 */
  10. #define EXTHIVERSION     0x00010005    /* 1.5 */
  11. #define EXTLOWVERSION    0x00000009    /* 0.9 */ 
  12. #define OWNER        0
  13. #define MONITOR      1
  14. #define MAX_CALL        3
  15. #define MAX_LINE        2
  16.  
  17.  
  18. #if defined (WIN32)
  19.     #define IS_WIN32 TRUE
  20. #else
  21.     #define IS_WIN32 FALSE
  22. #endif
  23.  
  24. #define IS_NT      IS_WIN32 && (BOOL)(GetVersion() < 0x80000000)
  25. #define IS_WIN32S  IS_WIN32 && (BOOL)(!(IS_NT) && (LOBYTE(LOWORD(GetVersion()))<4))
  26. #define IS_WIN95   (BOOL)(!(IS_NT) && !(IS_WIN32S)) && IS_WIN32
  27.  
  28. LPCTSTR lpszAppName = "lineGetCountry";
  29. LPCTSTR lpszTitle   = "lineGetCountry"; 
  30.  
  31. HINSTANCE hInst;   // current instance
  32. HWND hWnd;         // parent window handle
  33. HWND hListWnd;     // listbox
  34. HDC  hdc;
  35. TEXTMETRIC  tm ;
  36.  
  37. BOOL RegisterWin95( CONST WNDCLASS* lpwc );
  38.  
  39.  
  40. int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
  41.                       LPTSTR lpCmdLine, int nCmdShow)
  42. {
  43.    MSG      msg;
  44.    WNDCLASS wc;
  45.  
  46.    wc.style         = CS_HREDRAW | CS_VREDRAW;
  47.    wc.lpfnWndProc   = (WNDPROC)WndProc;       
  48.    wc.cbClsExtra    = 0;                      
  49.    wc.cbWndExtra    = 0;                      
  50.    wc.hInstance     = hInstance;              
  51.    wc.hIcon         = LoadIcon (hInstance, lpszAppName); 
  52.    wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
  53.    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  54.    wc.lpszMenuName  = lpszAppName;              
  55.    wc.lpszClassName = lpszAppName;              
  56.  
  57.    if ( IS_WIN95 )
  58.    {
  59.       if ( !RegisterWin95( &wc ) )
  60.          return( FALSE );
  61.    }
  62.    else if ( !RegisterClass( &wc ) )
  63.       return( FALSE );
  64.  
  65.    hInst = hInstance; 
  66.  
  67.    hWnd = CreateWindow( lpszAppName, 
  68.                         lpszTitle,    
  69.                         WS_OVERLAPPEDWINDOW, 
  70.                         CW_USEDEFAULT, 0, 
  71.                         CW_USEDEFAULT, 0,  
  72.                         NULL,              
  73.                         NULL,              
  74.                         hInstance,         
  75.                         NULL               
  76.                       );
  77.  
  78.    if ( !hWnd ) 
  79.       return( FALSE );
  80.  
  81.    ShowWindow( hWnd, nCmdShow ); 
  82.    UpdateWindow( hWnd );         
  83.  
  84.    while( GetMessage( &msg, NULL, 0, 0) )   
  85.    {
  86.       TranslateMessage( &msg ); 
  87.       DispatchMessage( &msg );  
  88.    }
  89.  
  90.    return( msg.wParam ); 
  91. }
  92.  
  93.  
  94. BOOL RegisterWin95( CONST WNDCLASS* lpwc )
  95. {
  96.     WNDCLASSEX wcex;
  97.  
  98.    wcex.style         = lpwc->style;
  99.    wcex.lpfnWndProc   = lpwc->lpfnWndProc;
  100.    wcex.cbClsExtra    = lpwc->cbClsExtra;
  101.    wcex.cbWndExtra    = lpwc->cbWndExtra;
  102.    wcex.hInstance     = lpwc->hInstance;
  103.    wcex.hIcon         = lpwc->hIcon;
  104.    wcex.hCursor       = lpwc->hCursor;
  105.    wcex.hbrBackground = lpwc->hbrBackground;
  106.    wcex.lpszMenuName  = lpwc->lpszMenuName;
  107.    wcex.lpszClassName = lpwc->lpszClassName;
  108.  
  109.    // Added elements for Windows 95.
  110.    //...............................
  111.    wcex.cbSize = sizeof(WNDCLASSEX);
  112.    wcex.hIconSm = LoadImage(wcex.hInstance, lpwc->lpszClassName, 
  113.                             IMAGE_ICON, 16, 16,
  114.                             LR_DEFAULTCOLOR );
  115.             
  116.    return RegisterClassEx( &wcex );
  117. }
  118.  
  119. #define CONFCALL    1
  120. #define CONSULT      2
  121.  
  122. enum CallState
  123. {
  124.     Idle,
  125.     Offering,
  126.     Accepted,
  127.     Dialtone,
  128.     Dialing,
  129.     Ringback,
  130.     Busy,
  131.     Special,
  132.     Connected,
  133.     Proceeding,
  134.     Conferenced,
  135.     Onholdconf,
  136.     Disconnected,
  137.     Unknown
  138. };
  139.  
  140. typedef struct tagMYINFO      // general application information
  141. {
  142.     HLINEAPP lineApp;         // instance handle TAPI gives back to us                                                                              through lineInitialize()
  143.     DWORD dwNumDevices;       // number of available devices
  144.     DWORD dwAPIVersion;       // API version the line supports
  145.      DWORD dwExtVersion;           // extended version
  146.     char szLocation[128];     // location        
  147.      char szCallingCard[128];  // calling card being used
  148.     char szAreaCode[4];       // area code       
  149.     char szCountry[128];      // calling card being used
  150. } MYINFO;
  151.  
  152. typedef struct tagLINEINFO  // information on an open line
  153. {
  154.     DWORD dwNumAddress;     // number of available addresses on the line 
  155.     HLINE hLine;            // handle to the line as returned by lineOpen 
  156.      DWORD dwLineID;         // the line ID of this line
  157.     char  szLineName[128];  // the line's name 
  158.  
  159. } MYLINEINFO;
  160.  
  161. typedef struct tagMYCALLINFO  //information on a call                     
  162. {
  163.     
  164. DWORD       eCallState;    // TAPI's line call State, set as user-defined enums
  165. DWORD      dwRequestID;   // requestID returned by async TAPI functions lineMakeCall/lineDropCall
  166. DWORD      dwAddressID;   // the originating address ID of the call being made 
  167. LPCSTR     lpszAddress;    
  168. HLINE     hLine;         // handle to the line 
  169. HCALL        hCall;         // handle to the call 
  170.    
  171. char szDialString[TAPIMAXDESTADDRESSSIZE];  //phone number being dialed
  172. char szDialStringOriginal[TAPIMAXDESTADDRESSSIZE];
  173. char szDialStringCanonical[TAPIMAXDESTADDRESSSIZE];
  174. char szCalledParty[TAPIMAXCALLEDPARTYSIZE]; // name of the party
  175. DWORD dwTranslateResults;
  176.         
  177. } MYCALLINFO;
  178.  
  179. enum CallAction     // Declare enum type CallAction (used in lineSetAppSpecific)
  180. {
  181.    HOLD,            // hold the call
  182.    TRANSFER,        // transfer the call
  183.    REDIRECT,        // redirect the call
  184.    DROP,            // drop the call
  185.    PARK             // park the call
  186. }; 
  187.  
  188. MYINFO myInfo;          //instance of MYINFO structure
  189. MYLINEINFO myLineInfo[MAX_LINE];  //instance of MYLINEINFO structure
  190. MYCALLINFO myCallInfo[MAX_CALL]; //array of MYCALLINFO strcuture
  191.  
  192. LONG lRet;        //return code
  193. char buf[BUFSIZE];    // buffer for debug message
  194.  
  195. DWORD dwLineID = 0;
  196. DWORD i;
  197. LINEEXTENSIONID        ext_id;
  198. LINEDEVCAPS            *plineDevCaps;
  199. LINEADDRESSCAPS        *plineAddressCaps;
  200. LINEADDRESSSTATUS     *plineAddressStat;
  201. LINECALLINFO            *plineCallInfo;
  202. LINECALLSTATUS         *plineCallStatus;
  203. LINECALLLIST            *plineCallList;
  204. LINEDEVSTATUS           *plineDevStatus;
  205. LINETRANSLATECAPS       *plineTranslateCaps;
  206. LINETRANSLATEOUTPUT  *plineTranslateOutput;
  207. LINECALLPARAMS           *plineCallParams;
  208. LINEDEVSTATUS           *plineDevStatus;
  209. LINEFORWARDLIST        *plineForwardList;
  210. LINETRANSLATECAPS       *plineTranslateCaps;
  211. LINEREQMAKECALL       lineReqMakeCall;
  212. VARSTRING               *pDeviceConfig;
  213. VARSTRING               *pDeviceId;
  214. VARSTRING               *pNonDirAddress;
  215.  
  216. LPLINELOCATIONENTRY  lineLocEntry;
  217. LPLINECARDENTRY        lineCardEntry;
  218. LINECOUNTRYLIST         *plineCountryList;
  219. LPLINECOUNTRYENTRY   lineCE;
  220.  
  221. LPSTR                lpData;
  222.  
  223. HICON                hIcon = NULL;        //used in lineGetID();
  224. DWORD                dwNumRings;    //used in lineGetNumRings();
  225. HCALL                hConsultCall; //handle to consultation linePrepareAddToConference, SetupConference
  226. HCALL                hConfCall; //handle to consultation linePrepareAddToConference, SetupConference   
  227. HCALL                hParkedCall;
  228.  
  229. DWORD                dwCompletionID;  //used in lineCompleteCall()
  230.  
  231. char                szName[128];
  232. char                szNumber[128];
  233. char                szDigits[128];
  234. char                szDevConfig[128];
  235.  
  236. LONG lRet;
  237. char buf[BUFSIZE];
  238.  
  239. LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
  240. {
  241.    switch( uMsg )
  242.    {
  243.       case WM_COMMAND :
  244.          switch( LOWORD( wParam ) )
  245.          {
  246.              case IDM_RUN :
  247.                plineCountryList = (LINECOUNTRYLIST *) calloc (1,                         
  248.                                     sizeof(LINECOUNTRYLIST)+1000);
  249.                plineCountryList->dwTotalSize = sizeof(LINECOUNTRYLIST) + 1000;
  250.              
  251.                //get country list
  252.                //........................
  253.                lRet = lineGetCountry(1, myInfo.dwAPIVersion, plineCountryList);
  254.                if (lRet == 0)
  255.                {
  256.                   lineCE = (LPLINECOUNTRYENTRY)((LPSTR)(plineCountryList) +                    
  257.                                          plineCountryList->dwCountryListOffset);
  258.                   strncpy(myInfo.szCountry, (LPSTR)(plineCountryList)+ 
  259.                   lineCE[0].dwCountryNameOffset,lineCE[0].dwCountryNameOffset);
  260.                   MessageBox (hWnd, myInfo.szCountry, "", MB_OK);
  261.               }
  262.               else 
  263.               {
  264.                  wsprintf ( buf,"lineGetCountry failed, err=x%lx", lRet);
  265.                  lineError(lRet);
  266.               }
  267.               free(plineCountryList); 
  268.               break;
  269.  
  270.          
  271.             case IDM_ABOUT :
  272.             {
  273.                 DialogBox( hInst, "AboutBox", hWnd, (DLGPROC)About );
  274.                break;
  275.             }
  276.  
  277.             case IDM_EXIT :
  278.             {
  279.                for (i = 0; i < myInfo.dwNumDevices; i++)
  280.                        lineClose(myLineInfo[i].hLine);
  281.                     lineShutdown(myInfo.lineApp);
  282.                DestroyWindow( hWnd );
  283.                break;
  284.             }
  285.             }                  
  286.                  
  287.          break;
  288.  
  289.       case WM_CREATE :
  290.       {
  291.          hdc = GetDC (hWnd) ;
  292.          GetTextMetrics (hdc, &tm) ;
  293.          ReleaseDC (hWnd, hdc) ;
  294.  
  295.          hListWnd = CreateWindowEx( 0, "listbox", 
  296.                         " ",    
  297.                         WS_CHILD | WS_VISIBLE,  
  298.                         tm.tmAveCharWidth, tm.tmHeight * 3, 
  299.                         tm.tmAveCharWidth * 16 +
  300.                                    GetSystemMetrics (SM_CXVSCROLL), 
  301.                         tm.tmHeight * 5,  
  302.                         hWnd,              
  303.                         NULL,              
  304.                         hInst,         
  305.                         NULL               
  306.                         );
  307.  
  308.          
  309.          //lineInitialize
  310.             //...............................................
  311.          lRet = lineInitialize(&myInfo.lineApp, hInst, lineCallback, NULL, &myInfo.dwNumDevices);
  312.          if (lRet == 0) 
  313.          {
  314.             wsprintf (buf, "lineInitialize suceeded!");
  315.               SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  316.            }
  317.          else 
  318.           {
  319.                wsprintf ( buf,"lineInitialize failed, err=x%lx",lRet);
  320.                SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  321.                lineError(lRet);
  322.                break;
  323.          }                    
  324.          
  325.          //lineNegotiateAPIVersion
  326.           //...............................................
  327.          lRet = lineNegotiateAPIVersion(myInfo.lineApp, 0, APILOWVERSION, APIHIVERSION, 
  328.                                            &myInfo.dwAPIVersion, &ext_id);
  329.          if (lRet == 0)                        
  330.          {
  331.             wsprintf (buf, "lineNegotiateAPIVersion suceeded!");
  332.               SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  333.          }
  334.          else 
  335.           {
  336.                wsprintf (buf, "lineNegotiateAPIVersion failed, err=x%lx",
  337.                            lRet);
  338.                SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  339.                lineError(lRet);
  340.                lineShutdown (myInfo.lineApp);
  341.             break;
  342.          }
  343.  
  344.           //lineNegotiateExtVersion
  345.           //...............................................
  346.          lRet = lineNegotiateExtVersion(myInfo.lineApp, 0, myInfo.dwAPIVersion, EXTLOWVERSION, 
  347.                                            EXTHIVERSION, &myInfo.dwExtVersion);
  348.          if (lRet == 0)                        
  349.          {
  350.             wsprintf (buf, "lineNegotiateExtVersion suceeded!");
  351.             SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  352.  
  353.          }
  354.           else 
  355.           {
  356.                wsprintf (buf, "lineNegotiateExtVersion failed, err=x%lx",
  357.                      lRet);
  358.               SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  359.               lineError(lRet);
  360.       
  361.          }
  362.  
  363.           //lineGetDevCaps
  364.           //for each line device, get capabilities until we find one that supports
  365.          //interactive voice 
  366.           //...............................................
  367.          plineDevCaps = (LINEDEVCAPS *) calloc (1, sizeof(LINEDEVCAPS)+1000);
  368.          plineDevCaps->dwTotalSize = sizeof(LINEDEVCAPS) + 1000;
  369.          for (i = 0; i < myInfo.dwNumDevices; i++)
  370.          {
  371.             lineGetDevCaps(myInfo.lineApp, i, myInfo.dwAPIVersion, 0, plineDevCaps);
  372.             if (plineDevCaps->dwMediaModes & LINEMEDIAMODE_INTERACTIVEVOICE) 
  373.             {
  374.                
  375.                myLineInfo[i].dwNumAddress = plineDevCaps->dwNumAddresses;
  376.                   myLineInfo[i].dwLineID = i;
  377.                    if (plineDevCaps->dwLineNameSize > 0)
  378.                           strcpy(myLineInfo[i].szLineName,((LPSTR)(plineDevCaps)+plineDevCaps->dwLineNameOffset));
  379.              }
  380.           }
  381.  
  382.          //lineOpen
  383.           //................................................................
  384.           lRet = lineOpen(myInfo.lineApp,myLineInfo[OWNER].dwLineID,&myLineInfo[OWNER].hLine,
  385.                            myInfo.dwAPIVersion,0,(DWORD)lineCallback, LINECALLPRIVILEGE_NONE,
  386.                             LINEMEDIAMODE_DATAMODEM, NULL);
  387.           if (lRet == 0)
  388.           {
  389.             wsprintf (buf, "lineOpen suceeded!");
  390.             SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;         }
  391.            else 
  392.            {
  393.                wsprintf ( buf,"lineOpen failed, err=x%lx", lRet);
  394.                SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  395.                lineError(lRet);
  396.           }
  397.        
  398.          break;
  399.       }
  400.       
  401.       case WM_SIZE:
  402.           MoveWindow(hListWnd,0, 0, LOWORD(lParam), HIWORD(lParam), TRUE);
  403.          break;
  404.  
  405.       case WM_DESTROY :
  406.               PostQuitMessage(0);
  407.               break;
  408.  
  409.       default :
  410.             return( DefWindowProc( hWnd, uMsg, wParam, lParam ) );
  411.    }
  412.  
  413.    return( 0L );
  414. }
  415.  
  416.  
  417.  
  418.  
  419. /****************************************************************************
  420.     FUNCTION: lineCallback
  421.     PURPOSE:  callback function handles line events
  422. ****************************************************************************/
  423. LRESULT CALLBACK lineCallback (DWORD dwDevice, DWORD dwMsg,
  424.                                        DWORD dwCallbackInst, DWORD dwParam1,
  425.                                        DWORD dwParam2,DWORD dwParam3)
  426. {
  427.    switch (dwMsg)
  428.    {
  429.       case LINE_CALLSTATE:
  430.        {
  431.             for (i = 0; i < MAX_CALL; i++)
  432.            {
  433.                 if (dwDevice = (DWORD) myCallInfo[i].hCall) 
  434.                  switch (dwParam1)
  435.                  {
  436.                     case LINECALLSTATE_IDLE:
  437.                         myCallInfo[i].eCallState = Idle;
  438.                   break;
  439.                     
  440.                     case LINECALLSTATE_OFFERING:
  441.                   myCallInfo[i].eCallState = Offering;
  442.                   break;
  443.                                    
  444.                     case LINECALLSTATE_ACCEPTED:
  445.                         myCallInfo[i].eCallState = Accepted;
  446.                         break;
  447.                     
  448.                     case LINECALLSTATE_DIALTONE:
  449.                         myCallInfo[i].eCallState = Dialtone;
  450.                   break;
  451.                     
  452.                     case LINECALLSTATE_DIALING:
  453.                         myCallInfo[i].eCallState = Dialing;
  454.                         break;
  455.                   
  456.                   case LINECALLSTATE_RINGBACK:
  457.                         myCallInfo[i].eCallState = Ringback;
  458.                         break;
  459.             
  460.                     case LINECALLSTATE_BUSY:
  461.                         myCallInfo[i].eCallState = Busy;
  462.                         break;
  463.             
  464.                     case LINECALLSTATE_SPECIALINFO:
  465.                         myCallInfo[i].eCallState = Special;
  466.                        break;
  467.             
  468.                     case LINECALLSTATE_CONNECTED:
  469.                        myCallInfo[i].eCallState = Connected;
  470.                   break;
  471.  
  472.                     case LINECALLSTATE_PROCEEDING:
  473.                         myCallInfo[i].eCallState = Proceeding;
  474.                        break;
  475.             
  476.                     case LINECALLSTATE_CONFERENCED:
  477.                         myCallInfo[i].eCallState = Conferenced;
  478.                        break;
  479.             
  480.                     case LINECALLSTATE_ONHOLDPENDCONF:
  481.                         break;
  482.                 
  483.                case LINECALLSTATE_DISCONNECTED:
  484.                         myCallInfo[i].eCallState = Disconnected;
  485.                        break;
  486.             
  487.                     case LINECALLSTATE_UNKNOWN:
  488.                         myCallInfo[i].eCallState = Unknown;
  489.                        break;
  490.        
  491.              }
  492.           }
  493.        }
  494.  
  495.        case LINE_MONITORMEDIA:
  496.            break;
  497.  
  498.        case LINE_MONITORDIGITS:
  499.           break;
  500.  
  501.          case LINE_MONITORTONE:
  502.           break;
  503.    
  504.        //error handling for functions completed asynchronously
  505.         //.....................................................
  506.        case LINE_REPLY:
  507.         {
  508.             for (i = 0; i < MAX_CALL; i++)
  509.            {
  510.                 if (dwParam1 = myCallInfo[i].dwRequestID)
  511.                {
  512.                    if (dwParam2 != 0)
  513.                    {
  514.                        lineError((LONG) dwParam2);
  515.                        break;
  516.                    }
  517.                }
  518.            }
  519.         break;
  520.         }
  521.  
  522.         case LINE_GENERATE:
  523.           break;
  524.      
  525.        case LINE_REQUEST:
  526.          break;
  527.  
  528.         case LINE_GATHERDIGITS:
  529.            break;
  530.    }
  531.  
  532.    return (TRUE);
  533.  
  534.  
  535. /****************************************************************************
  536.     FUNCTION: lineError
  537.     PURPOSE:  line error messages
  538. ****************************************************************************/
  539. void lineError (LONG lrc)
  540. {
  541.  switch (lrc) {
  542.     case LINEERR_INVALAPPHANDLE:
  543.        MessageBox (hWnd, "Invalid app handle.", "", MB_OK);
  544.        break;
  545.     case LINEERR_BADDEVICEID:
  546.        MessageBox (hWnd,"The specified line device ID is out of range.", "", 
  547.                    MB_OK);
  548.        break;
  549.     case LINEERR_INCOMPATIBLEAPIVERSION:
  550.        MessageBox (hWnd, "Incompatible API version.", "", MB_OK);
  551.        break;
  552.     
  553.     case LINEERR_ADDRESSBLOCKED:
  554.        MessageBox (hWnd, "Address was blocked.", "", MB_OK);
  555.        break;
  556.  
  557.     case LINEERR_BEARERMODEUNAVAIL:
  558.        MessageBox (hWnd, "Bearer Mode Unavailable.", "", MB_OK);
  559.        break;
  560.  
  561.     case LINEERR_CALLUNAVAIL:
  562.        MessageBox (hWnd, "Call appearances in use..", "", MB_OK);
  563.        break;
  564.  
  565.     case LINEERR_INUSE:
  566.        MessageBox (hWnd, "Line in Use.", "", MB_OK);
  567.        break;
  568.     
  569.     case LINEERR_INVALADDRESS:
  570.        MessageBox (hWnd, "Invalid Address.", "", MB_OK);
  571.        break;
  572.  
  573.     case LINEERR_INVALADDRESSID:
  574.        MessageBox (hWnd, "Invalid Address ID.", "", MB_OK);
  575.        break;
  576.  
  577.     case LINEERR_INVALCALLPARAMS:
  578.        MessageBox (hWnd, "Invalid Address ID.", "", MB_OK);
  579.        break;
  580.      
  581.     case LINEERR_INCOMPATIBLEEXTVERSION:
  582.        MessageBox (hWnd, "Incompatible extension version.","", MB_OK);
  583.        break;
  584.     case LINEERR_NOMEM:
  585.        MessageBox (hWnd, "No memory","", MB_OK);
  586.        break;
  587.     case LINEERR_NODRIVER:
  588.        MessageBox (hWnd, "No driver loaded", "", MB_OK);
  589.        break;
  590.     case LINEERR_RESOURCEUNAVAIL:
  591.        MessageBox (hWnd, "Resource overcommittment", "", MB_OK);
  592.        break;
  593.     case LINEERR_INVALPRIVSELECT:
  594.        MessageBox (hWnd, "Requested invalid priviledges", "", MB_OK);
  595.        break;
  596.     case LINEERR_INVALMEDIAMODE:
  597.        MessageBox (hWnd, "Requested invalid media mode", "", MB_OK);
  598.        break;
  599.     case LINEERR_LINEMAPPERFAILED:
  600.        MessageBox (hWnd, "Line mapper failed", "", MB_OK);
  601.        break;
  602.     case LINEERR_INVALPOINTER:
  603.        MessageBox (hWnd, "The specified pointer parameter is invalid.",
  604.                    "", MB_OK);
  605.        break;
  606.     case LINEERR_OPERATIONFAILED:
  607.        MessageBox (hWnd, "Operation failed.", "", MB_OK);
  608.        break;
  609.     case LINEERR_INVALLINEHANDLE:
  610.        MessageBox (hWnd, "Invalid line handle", "", MB_OK);
  611.        break;
  612.     case LINEERR_INVALCALLHANDLE:
  613.        MessageBox (hWnd, "Invalid call handle", "", MB_OK);
  614.        break;
  615.     case LINEERR_INVALCALLSELECT:
  616.        MessageBox (hWnd, "Invalid call selection", "", MB_OK);
  617.        break;
  618.     case LINEERR_NODEVICE:
  619.        MessageBox (hWnd, "No associated device for given class",
  620.                    "", MB_OK);
  621.        break;
  622.     case LINEERR_OPERATIONUNAVAIL:
  623.        MessageBox (hWnd, "The operation is unavailable",
  624.                    "", MB_OK);
  625.        break;
  626.     case LINEERR_INVALPARAM:
  627.         MessageBox(hWnd, "Invalid Paramater", "", MB_OK);
  628.        break; 
  629.  
  630.     case LINEERR_TARGETNOTFOUND:
  631.         MessageBox(hWnd, "Target Not Found", "", MB_OK);
  632.        break; 
  633.  
  634.    case LINEERR_NOREQUEST:
  635.       MessageBox(hWnd, "No outstanding Assisted Telephony requests.", "", MB_OK);
  636.        break; 
  637.    }
  638. }
  639.  
  640. LRESULT CALLBACK Dial ( HWND hDlg,           // window handle of the dialog box
  641.                         UINT message,        // type of message
  642.                         WPARAM wParam,       // message-specific information
  643.                         LPARAM lParam)
  644. {
  645.    switch (message) 
  646.    {
  647.        case WM_INITDIALOG:  // message: initialize dialog box
  648.                return (TRUE);
  649.  
  650.        case WM_COMMAND:                              // message: received a command
  651.          if (   LOWORD(wParam) == IDOK )        // "OK" box selected?
  652.          {
  653.             GetDlgItemText(hDlg, IDC_NAME, szName, 128);
  654.                 GetDlgItemText(hDlg, IDC_NUMBER, szNumber, 128);
  655.                                       
  656.  
  657.                 // put up a dialog box to obtain a string to dial from the user
  658.                //...........................................................
  659.                strcpy(myCallInfo[0].szDialStringOriginal, szNumber); 
  660.                
  661.                //allocate buffer for the LINEADDRESSCAPS strucuture 
  662.                //...................................................
  663.                plineTranslateOutput = (LINETRANSLATEOUTPUT *) calloc (1, sizeof(LINETRANSLATEOUTPUT)+1000);
  664.             plineTranslateOutput->dwTotalSize = sizeof(LINETRANSLATEOUTPUT) + 1000;
  665.               
  666.                // translate the Address to a dialable address and Canonical address
  667.                //.....................................................................
  668.                lRet = lineTranslateAddress(myInfo.lineApp, myLineInfo[OWNER].dwLineID, myInfo.dwAPIVersion,
  669.                                            myCallInfo[0].szDialStringOriginal, 0, 0, plineTranslateOutput);
  670.                               
  671.                if (lRet == 0)
  672.                {
  673.                        
  674.                    strncpy(myCallInfo[0].szDialString, (LPSTR)(plineTranslateOutput)
  675.                             + plineTranslateOutput->dwDialableStringOffset,
  676.                              plineTranslateOutput->dwDialableStringSize); 
  677.     
  678.                     strncpy(myCallInfo[0].szDialStringCanonical,(LPSTR)(plineTranslateOutput) 
  679.                             + plineTranslateOutput->dwDisplayableStringOffset,
  680.                             plineTranslateOutput->dwDisplayableStringSize); 
  681.                                            
  682.                    myCallInfo[0].dwTranslateResults = plineTranslateOutput->dwTranslateResults;
  683.                 }
  684.  
  685.                else 
  686.                {
  687.                     wsprintf ( buf,"lineTranslateAddress failed, err=x%lx", lRet);
  688.                     lineError(lRet);
  689.                    break;
  690.             }
  691.            
  692.                //lineMakeCall
  693.                //................................................................
  694.                           
  695.                plineCallParams = (LINECALLPARAMS *) calloc (1, sizeof(LINECALLPARAMS)+1000);
  696.             plineCallParams->dwTotalSize = sizeof(LINECALLPARAMS) + 1000;
  697.  
  698.                plineCallParams->dwBearerMode = LINEBEARERMODE_VOICE;
  699.                plineCallParams->dwMediaMode =  LINEMEDIAMODE_DATAMODEM;
  700.                plineCallParams->dwCallParamFlags = LINECALLPARAMFLAGS_IDLE;
  701.                plineCallParams->dwAddressMode    = LINEADDRESSMODE_ADDRESSID;
  702.                plineCallParams->dwAddressID    = 0;
  703.                plineCallParams->dwMinRate    = 1200;
  704.                plineCallParams->dwMaxRate    = 2400;
  705.                             
  706.                lRet = lineMakeCall(myLineInfo[OWNER].hLine,&myCallInfo[0].hCall, 
  707.                                       myCallInfo[0].szDialString ,0,  plineCallParams);
  708.            
  709.             if (lRet > 0)
  710.                {
  711.                wsprintf (buf, "lineMakeCall suceeded!");
  712.                SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;               
  713.                    myCallInfo[0].dwRequestID = lRet;
  714.                 }
  715.             else 
  716.                {
  717.                    wsprintf ( buf,"lineMakeCall failed, err=x%lx", lRet);
  718.                     lineError(lRet);
  719.                    break;
  720.             }
  721.             
  722.             EndDialog(hDlg, TRUE);        // Exit the dialog
  723.             return (TRUE);
  724.          }
  725.  
  726.             if (   LOWORD(wParam) == IDCANCEL)         // "OK" box selected?
  727.          {
  728.             EndDialog(hDlg, TRUE);        // Exit the dialog
  729.             return (TRUE);
  730.          }
  731.          break;
  732.  
  733.  
  734.    }
  735.  
  736.    return (FALSE); 
  737. }
  738.  
  739.  
  740. LRESULT CALLBACK About( HWND hDlg,           
  741.                         UINT message,        
  742.                         WPARAM wParam,       
  743.                         LPARAM lParam)
  744. {
  745.    switch (message) 
  746.    {
  747.        case WM_INITDIALOG: 
  748.                return (TRUE);
  749.  
  750.        case WM_COMMAND:                              
  751.                if (   LOWORD(wParam) == IDOK         
  752.                    || LOWORD(wParam) == IDCANCEL)    
  753.                {
  754.                        EndDialog(hDlg, TRUE);        
  755.                        return (TRUE);
  756.                }
  757.                break;
  758.    }
  759.  
  760.    return (FALSE); 
  761. }
  762.  
  763.  
  764.